<template>
	<view class="product">
		<view class="product-main">
			<view class="product-main-li" v-for="(item, index) of list" :key="index">
				<view class="product-main-li-head" @click="cli_isshow(item, index)">
					<text class="product-main-li-head-txt font_blod">{{item.partsName}}</text>
					<image class="product-main-li-head-img" v-if="item.isshow" src="../../../static/manufacturers/top.png" mode=""></image>
					<image class="product-main-li-head-img" v-else src="../../../static/manufacturers/btm.png" mode=""></image>
				</view>
				<view class="product-main-li-main" v-if="item.isshow == true">
					<view class="product-main-li-main-li" :class="[ite.num? 'back0' : '']" v-for="(ite, ind) of item.zsyhPlatformPartsattributeList" :key="ind">
						<view class="pmlml-left">
							<image class="pmlml-left-img" @click="previewImage(ite.attributeLogo)" :src=ite.attributeLogo mode=""></image>
						</view>
						<view class="pmlml-right">
							<view class="pmlml-right-one font_blod">
								{{ite.attributeName}}
							</view>
							<view class="pmlml-right-two">
								<text class="pmlml-right-two-txt"  v-if="ite.isPost == 1">包邮 偏远地区补差价</text>
								<text class="baoyou-no" v-else>不包邮</text>
							</view>
							<view class="pmlml-right-three">
								<view class="pmlml-right-three-box">
									合同价:￥<text class="pmlml-right-three-box-txt">{{ite.attributeContractPrice}}</text>/套
								</view>
								<view class="pmlml-right-three-box">
									售价:<text class="pmlml-right-three-box-txt2">￥</text><text
										class="pmlml-right-three-box-txt pmlml-right-three-box-txt2 font_blod">{{ite.attributeSalePrice}}</text>/套
								</view>
							</view>
							<view class="pmlml-right-four">
								<text class="pmlml-right-four-txt">数量</text>
								<input v-model="ite.num" placeholder-class="inputplace1" placeholder="请输入数量" class="pmlml-right-four-input" type="digit" value="" />
								<text class="pmlml-right-four-txt">个</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="product-btn">
			<view class="product-btnbox font_blod" @click="cli_btn">
				确认添加
			</view>
		</view>
	</view>
</template>

<script>
	import allapi from '../api/index.js'
	export default {
		data() {
			return {
				factoryId: uni.getStorageSync('id_factory'),
				list: [],
				id: uni.getStorageSync('id_factory_order')
			}
		},
		mounted() {
			this.getPartsListByFactoryId()
		},
		methods: {
			// 图片预览
			previewImage(item, index){
				console.log(item);
				let lis = item.split()
				wx.previewImage({
				  current: 0, // 当前显示图片的http链接
				  urls: lis // 需要预览的图片http链接列表
				})
			},
			// 点击隐藏列表
			cli_isshow (item, index) {
				let list = this.list
				item.isshow = !item.isshow
			},
			// 点击确认添加
			cli_btn () {
				let list = this.list
				let alllist = []
				for (let i in list) {
					let lis2 = list[i].zsyhPlatformPartsattributeList
					let lis3 = lis2.filter((item)=> {
						if (item.num) {
							console.log(111111,item);
							return item
						}
					})
					alllist = alllist.concat(lis3)
				}
				let putmsg = alllist.map((item) => {
					return {
						partsId: item.partsId,
						attributeId: item.id,
						count: item.num,
						price: item.attributeSalePrice
					}
				})
				if (alllist.length > 0) {
					this.savePartsAttributeToOrder(putmsg)
				}else {
					uni.showToast({
						title:'请先输入需要添加产品的数量',
						icon: 'none'
					})
				}
			},
			// 添加产品
			savePartsAttributeToOrder (partsJson) {
				uni.request({
					url: allapi.savePartsAttributeToOrder,
					data: {
						id: this.id,
						partsJson: partsJson
					},
					success: (res) => {
						console.log(res);
						uni.showToast({
							title: res.data.msg,
							icon:'none'
						})
						uni.navigateBack()
					}
				})
			},
			// 获取列表
			getPartsListByFactoryId() {
				uni.request({
					url: allapi.getPartsListByFactoryId,
					data: {
						factoryId: this.factoryId
					},
					success: (res) => {
						console.log(res);
						let dat = res.data.data
						let lis = []
						dat.map( (item) => {
							lis.push(Object.assign({},item,{isshow: false}))
						})
						this.list = lis
						console.log(lis);
					}
				})
			},
		}
	}
</script>

<style scoped>
	
	.product {
		padding-bottom: 180rpx;
		/* position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		display: flex;
		flex-direction: column; */
	}

	.product-main {
		flex: 1;
		overflow: auto;
	}

	.product-btn {
		position: fixed;
		width: 100%;
		bottom: 100rpx;
		z-index: 666;
	}
	.product-btnbox {
		/* width: 184rpx; */
		margin: 0 16rpx;
		height: 92rpx;
		line-height: 92rpx;
		background: #5DD4D6;
		border-radius: 46rpx;
		font-size: 36rpx;
		text-align: center;
		color: #FFFFFF;
	}

	.product-main-li {
		background: #F3F5F7;
	}

	.product-main-li-head {
		margin: 24rpx;
		height: 108rpx;
		background: #FFFFFF;
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #FFFFFF;
		padding-left: 16rpx;
		padding-right: 24rpx;
	}

	.product-main-li-head-txt {
		font-size: 32rpx;
		color: #333333;
	}

	.product-main-li-head-img {
		width: 36rpx;
		height: 36rpx;
	}
	.product-main-li-main {
		margin: 0 24rpx;
	}
	.product-main-li-main-li {
		border-bottom: 1rpx solid #E9EEF1;
		display: flex;
		padding: 24rpx;
	}
	.product-main-li-main-li:last-of-type{
		border: 0;
	}
	.back0 {
		background: #E2EAEF;
	}
	.pmlml-left-img {
		width: 132rpx;
		height: 132rpx;
		border-radius: 8rpx;
	}

	.pmlml-right {
		margin-left: 16rpx;
		flex: 1;
	}

	.pmlml-right-one {
		font-size: 28rpx;
		color: #333333;
		line-height: 40rpx;
	}

	.pmlml-right-two {
		margin-top: 5rpx;
	}

	.pmlml-right-two-txt {
		width: 68rpx;
		height: 34rpx;
		line-height: 34rpx;
		text-align: center;
		border-radius: 6rpx;
		border: 2rpx solid #28CD50;
		font-size: 24rpx;
		font-weight: 400;
		color: #28CD50;
		padding: 0 12rpx;
	}

	.pmlml-right-three {
		display: flex;
		justify-content: space-between;
		margin-top: 6rpx;
	}

	.pmlml-right-three-box {
		font-size: 24rpx;
		font-weight: 400;
		color: #333333;
	}

	.pmlml-right-three-box-txt {
		font-size: 32rpx;
		letter-spacing: 1rpx;
	}

	.pmlml-right-three-box-txt2 {
		color: #EF691C;
	}

	.pmlml-right-four {
		display: flex;
		align-items: center;
		margin-top: 10rpx;
		color: #333333;
	}

	.pmlml-right-four-txt {
		font-size: 24rpx;
	}

	.pmlml-right-four-input {
		width: 124rpx;
		height: 44rpx;
		line-height: 44rpx;
		border-radius: 8rpx;
		text-align: center;
		font-size: 32rpx;
		border: 2rpx solid #ccc;
		margin: 0 16rpx;
		/* color: #333333; */
		color: #5DD4D6 !important;
	}
	/deep/ .inputplace1 {
		font-size: 20rpx;
		color: #999999;
		font-weight: normal;
	}
</style>
